package jeecg.business.service.impl.send;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import jeecg.business.entity.send.SendMessEnterEntity;
import jeecg.business.entity.site.SiteWordEntity;
import jeecg.business.service.send.SendMessEnterServiceI;
import org.jeecgframework.core.common.service.impl.CommonServiceImpl;

@Service("sendMessEnterService")
@Transactional
public class SendMessEnterServiceImpl extends CommonServiceImpl implements SendMessEnterServiceI {
	public String [] getSelectetId(String xxid){
		String sql = " select qyid from nms_send_mess_enter where xxid = '"+xxid+"'";
		List<String> idlist = getJdbcTemplate().queryForList(sql, String.class);
		if(idlist != null){
			return idlist.toArray(new String[0]);
		}
		return null;
	}
	
	public String getSelectName(String xxid){
		String str = "";
		String sql = " select e.name from nms_send_mess_enter s ,nms_enter e where e.id = s.qyid and xxid = '"+xxid+"'";
		List<String> namelist = getJdbcTemplate().queryForList(sql, String.class);
		if(namelist != null)
			for(String name : namelist)
				str += name+",";
		return str;
	}
	
	public void assignEnter(String xxid, String ids){
		String [] keyarray = ids.split(",");
		SendMessEnterEntity sme = null;
		for(String key : keyarray){
			if(getJdbcTemplate().queryForInt(" select count(1) from nms_send_mess_enter where xxid = '"+xxid+"' and qyid = '"+key+"'")==0){
				sme = new SendMessEnterEntity();
				sme.setXxid(xxid);
				sme.setQyid(key);
				save(sme);
			}
		}
	}
	
	public void delEnter(String xxid , String ids){
		ids = "'"+ids.replace(",", "','")+"'";
		getJdbcTemplate().execute(" delete from nms_send_mess_enter where xxid = '"+xxid+"' and qyid in ("+ids+")");
	}
}